# Setup Versions
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/Version.h)


# Source files for toadlet_egg
set (EGG_SRC
	Assert.cpp
	Error.cpp
	Exception.cpp
	Logger.cpp
	MathFormatting.cpp
	SOSLoggerListener.cpp
	Object.cpp
	Profile.cpp
	Random.cpp
	String.cpp
	UUID.cpp
	Version.cpp
)

set (EGG_IO_SRC
	io/DataStream.cpp
	io/FileStream.cpp
	io/MemoryStream.cpp
	io/SocketStream.cpp
)

set (EGG_MATH_SRC
	math/Capsule.cpp
	math/Math.cpp
	math/Matrix3x3.cpp
	math/Matrix4x4.cpp
	math/Plane.cpp
	math/Quaternion.cpp
	math/Sphere.cpp
)

set (EGG_MATHFIXED_SRC
	mathfixed/Capsule_fixed.cpp
	mathfixed/Math_fixed.cpp
	mathfixed/Matrix3x3_fixed.cpp
	mathfixed/Matrix4x4_fixed.cpp
	mathfixed/Plane_fixed.cpp
	mathfixed/Quaternion_fixed.cpp
	mathfixed/Sphere_fixed.cpp
)

set (EGG_NET_SRC
	net/Socket.cpp
)

set (EGG_PLATFORM_POSIX_SRC
	platform/posix/PosixDynamicLibrary.cpp
	platform/posix/PosixErrorHandler.cpp
	platform/posix/PosixMutex.cpp
	platform/posix/PosixSystem.cpp
	platform/posix/PosixThread.cpp
	platform/posix/PosixWaitCondition.cpp
)

set (EGG_PLATFORM_ANDROID_SRC
	platform/android/AndroidAssetArchive.cpp
	platform/android/JStream.cpp
)

set (EGG_PLATFORM_OSX_SRC
	platform/osx/OSXBundleArchive.mm
	platform/posix/PosixErrorHandler_osx.mm
)

set (EGG_PLATFORM_WIN32_SRC
	platform/win32/Win32DynamicLibrary.cpp
	platform/win32/Win32ErrorHandler.cpp
	platform/win32/Win32Mutex.cpp
	platform/win32/Win32ResourceArchive.cpp
	platform/win32/Win32System.cpp
	platform/win32/Win32Thread.cpp
	platform/win32/Win32WaitCondition.cpp
)


# Headers
set (EGG_HEADERS
	Assert.h
	BaseResource.h
	Collection.h
	Categories.h
	DynamicLibrary.h
	EndianConversion.h
	Error.h
	Event.h
	Exception.h
	Extents.h
	Interface.h
	IntrusivePointer.h
	Logger.h
	LoggerListener.h
	MathConversion.h
	MathFormatting.h
	Map.h
	Mutex.h
	Object.h
	PointerCounter.h
	Profile.h
	Random.h
	Resource.h
	ResourceDestroyedListener.h
	Runnable.h
	SharedPointer.h
	SOSLoggerListener.h
	String.h
	System.h
	Thread.h
	Type.h
	WaitCondition.h
	WeakPointer.h
	UUID.h
	Version.h
)

set (EGG_IO_HEADERS
	io/Archive.h
	io/DataStream.h
	io/FileStream.h
	io/MemoryStream.h
	io/SocketStream.h
	io/Stream.h
)

set (EGG_MATH_HEADERS
	math/AABox.h
	math/BaseMath.h
	math/Capsule.h
	math/EulerAngle.h
	math/Math.h
	math/Matrix3x3.h
	math/Matrix4x4.h
	math/Plane.h
	math/Quaternion.h
	math/Segment.h
	math/Sphere.h
	math/Vector2.h
	math/Vector3.h
	math/Vector4.h
)

set (EGG_MATHFIXED_HEADERS
	mathfixed/AABox.h
	mathfixed/BaseMath.h
	mathfixed/Capsule.h
	mathfixed/EulerAngle.h
	mathfixed/Math.h
	mathfixed/Matrix3x3.h
	mathfixed/Matrix4x4.h
	mathfixed/Plane.h
	mathfixed/Quaternion.h
	mathfixed/Segment.h
	mathfixed/Sphere.h
	mathfixed/Vector2.h
	mathfixed/Vector3.h
	mathfixed/Vector4.h
)

set (EGG_NET_HEADERS
	net/Socket.h
)

set (EGG_PLATFORM_POSIX_HEADERS
	platform/posix/PosixDynamicLibrary.h
	platform/posix/PosixErrorHandler.h
	platform/posix/PosixMutex.h
	platform/posix/PosixSystem.h
	platform/posix/PosixThread.h
	platform/posix/PosixWaitCondition.h
)

set (EGG_PLATFORM_ANDROID_HEADERS
	platform/android/AndroidAssetArchive.h
	platform/android/JStream.h
)

set (EGG_PLATFORM_OSX_HEADERS
	platform/osx/OSXBundleArchive.h
)

set (EGG_PLATFORM_WIN32_HEADERS
	platform/win32/Win32DynamicLibrary.h
	platform/win32/Win32ErrorHandler.h
	platform/win32/Win32Mutex.h
	platform/win32/Win32ResourceArchive.h
	platform/win32/Win32System.h
	platform/win32/Win32Thread.h
	platform/win32/Win32WaitCondition.h
)


# Bundle source
source_group ("Source Files\\\\io" FILES ${EGG_IO_SRC})
source_group ("Source Files\\\\net" FILES ${EGG_NET_SRC})


# Bundle headers
source_group ("Header Files\\\\io" FILES ${EGG_IO_HEADERS})
source_group ("Header Files\\\\net" FILES ${EGG_NET_HEADERS})


# Sources, headers and namespaces
set (EGG_SRC ${EGG_SRC} ${EGG_IO_SRC} ${EGG_NET_SRC})
set (EGG_HEADERS ${EGG_HEADERS} ${EGG_IO_HEADERS} ${EGG_NET_HEADERS})
set (EGG_NAMESPACES ${EGG_NAMESPACES} io net)


# Always build both fixed & floating point math
# But include neither in the autogenerated header files (eg. not present in EGG_NAMESPACES)
set (EGG_SRC ${EGG_SRC} ${EGG_MATHFIXED_SRC})
set (EGG_HEADERS ${EGG_HEADERS} ${EGG_MATHFIXED_HEADERS})
source_group ("Source Files\\\\mathfixed" FILES ${EGG_MATHFIXED_SRC})
source_group ("Header Files\\\\mathfixed" FILES ${EGG_MATHFIXED_HEADERS})
set (EGG_SRC ${EGG_SRC} ${EGG_MATH_SRC})
set (EGG_HEADERS ${EGG_HEADERS} ${EGG_MATH_HEADERS})
source_group ("Source Files\\\\math" FILES ${EGG_MATH_SRC})
source_group ("Header Files\\\\math" FILES ${EGG_MATH_HEADERS})


# Platform specific files
if (TOADLET_PLATFORM_WIN32)	
	source_group ("Source Files\\\\platform\\\\win32" FILES ${EGG_PLATFORM_WIN32_SRC})
	source_group ("Header Files\\\\platform\\\\win32" FILES ${EGG_PLATFORM_WIN32_HEADERS})
	set (EGG_SRC ${EGG_SRC} ${EGG_PLATFORM_WIN32_SRC})
	set (EGG_HEADERS ${EGG_HEADERS} ${EGG_PLATFORM_WIN32_HEADERS})
elseif (TOADLET_PLATFORM_POSIX) 
	source_group ("Source Files\\\\platform\\\\posix" FILES ${EGG_PLATFORM_POSIX_SRC})
	source_group ("Header Files\\\\platform\\\\posix" FILES ${EGG_PLATFORM_POSIX_HEADERS})
	set (EGG_SRC ${EGG_SRC} ${EGG_PLATFORM_POSIX_SRC})
	set (EGG_HEADERS ${EGG_HEADERS} ${EGG_PLATFORM_POSIX_HEADERS})

	if (TOADLET_PLATFORM_OSX)
		source_group ("Source Files\\\\platform\\\\osx" FILES ${EGG_PLATFORM_OSX_SRC})
		source_group ("Header Files\\\\platform\\\\osx" FILES ${EGG_PLATFORM_OSX_HEADERS})
		set (EGG_SRC ${EGG_SRC} ${EGG_PLATFORM_OSX_SRC})
		set (EGG_HEADERS ${EGG_HEADERS} ${EGG_PLATFORM_OSX_HEADERS})
		find_library (FOUNDATION_LIBS Foundation)
		set (EGG_LIBS objc ${EGG_LIBS} ${FOUNDATION_LIBS})
	endif (TOADLET_PLATFORM_OSX)

	if (TOADLET_PLATFORM_ANDROID)
		source_group ("Source Files\\\\platform\\\\android" FILES ${EGG_PLATFORM_ANDROID_SRC})
		source_group ("Header Files\\\\platform\\\\android" FILES ${EGG_PLATFORM_ANDROID_HEADERS})
		set (EGG_SRC ${EGG_SRC} ${EGG_PLATFORM_ANDROID_SRC})
		set (EGG_HEADERS ${EGG_HEADERS} ${EGG_PLATFORM_ANDROID_HEADERS})
		set (EGG_LIBS ${EGG_LIBS} log)
	else (TOADLET_PLATFORM_ANDROID)
		# Android does not have a separate pthread library
		set (EGG_LIBS ${EGG_LIBS} pthread)
	endif (TOADLET_PLATFORM_ANDROID)
endif (TOADLET_PLATFORM_WIN32)


# Give the headers and namespaces parent scope for inclusion into the master egg.h file
set (EGG_HEADERS ${EGG_HEADERS} PARENT_SCOPE)
set (EGG_NAMESPACES ${EGG_NAMESPACES} PARENT_SCOPE)


# If we are using swig create the wrapper file from the interface files
if (SWIG_FOUND AND TOADLET_EGG_INT)
	swig_wrap_files (egg_wrap.cpp egg ${TOADLET_EGG_INT} "${TOADLET_EGG_INT_DEPS}")	
	set (EGG_SRC ${EGG_SRC} egg_wrap.cpp)
endif (SWIG_FOUND AND TOADLET_EGG_INT)


# Dynamic library
if (TOADLET_BUILD_DYNAMIC)
	add_library (toadlet_egg SHARED ${EGG_SRC} ${EGG_HEADERS})
	set_target_properties (toadlet_egg PROPERTIES ${DYNAMIC_LIB_PROPS})
	target_link_libraries (toadlet_egg ${EGG_LIBS})
	install (TARGETS toadlet_egg DESTINATION ${LIB_INSTALL_DIR})
endif (TOADLET_BUILD_DYNAMIC)


# Static library
if (TOADLET_BUILD_STATIC)
	add_library (toadlet_egg_s STATIC ${EGG_SRC} ${EGG_HEADERS})
	set_target_properties (toadlet_egg_s PROPERTIES ${STATIC_LIB_PROPS})
	target_link_libraries (toadlet_egg_s ${EGG_LIBS})
	install (TARGETS toadlet_egg_s DESTINATION ${LIB_INSTALL_DIR})

	# HACK: install the library on iOS. This will disappear once cmake issue:0012506 is resolved. 
	if (TOADLET_PLATFORM_IOS)
	    install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/\$ENV{CONFIGURATION}\$ENV{EFFECTIVE_PLATFORM_NAME}/ DESTINATION ${LIB_INSTALL_DIR} FILES_MATCHING PATTERN "*.a")
	endif (TOADLET_PLATFORM_IOS)
endif (TOADLET_BUILD_STATIC)


